package com.dtdream.emr;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.hadoop.hive.ql.exec.UDF;

import java.net.URLDecoder;

public final class KeywordResolver extends UDF {

    public String evaluate(String s) throws Exception {
        StringBuilder sb = new StringBuilder();
        if (null == s || "".equals(s)) {
            return sb.toString();
        }
        String json = s.replaceAll("^\"|\"$", "");
        try {
            JSONArray array = JSON.parseArray(json);
            for (Object object : array) {
                sb.append(((JSONObject) object).getString("name")).append(" ");
            }
        } catch (Exception e) {

        }
        return sb.length() > 0 ? sb.deleteCharAt(sb.length() - 1).toString() : sb.toString();
    }
}
